package com.zjw.zy.coreui.fragment.memorandum

import android.content.ClipData
import android.content.ClipboardManager
import android.os.Bundle
import android.util.TypedValue
import android.view.View
import android.widget.EditText
import com.zjw.zy.R
import com.zjw.zy.base.BaseFragment
import com.zjw.zy.ext.edit
import com.zjw.zy.ext.longToast
import com.zjw.zy.ext.mainActivity
import com.zjw.zy.utils.ResourcesUtils
import com.zjw.zy.utils.WindowUtils

/**
 * @author     ：zhong.jw
 * @date       ：Created in 2022/10/20 14:57
 * @description：展示纯文字的地方，可以进行微信分享
 */
class TextFragment : BaseFragment() {

    companion object {
        const val TEXT_KEY = "TextFragment_TEXT_KEY";
        const val TEXT_SIZE_KEY = "TextFragment_TEXT_SIZE_KEY";
        private const val TAG = "TextFragment"
    }

    private val mText: EditText by lazy { findViewById(R.id.fragment_text_text) }

    override fun onPageEnter() {
        WindowUtils.TopBar.showBack()
        WindowUtils.TopBar.setTopBarLabelText("")
        WindowUtils.FootBar.hide()
        WindowUtils.TopBar.hideAllRightButton()

        WindowUtils.TopBar.show1RightButton(ResourcesUtils.getDrawable(R.drawable.bd_ocr_confirm)) {
            //微信分享
            "微信分享".longToast()
        }

    }

    override fun onViewRestore(savedInstanceState: Bundle?) {

    }

    override fun onSubscribe() {

    }

    override fun onBindViewListener() {

    }

    override fun onBindViewValue() {

        arguments?.getString(TEXT_KEY)?.let { str ->
            mText.setText(str)
            mText.edit()

            //复制进剪切板
            mainActivity().getSystemService(ClipboardManager::class.java).apply {
                this.setPrimaryClip(ClipData.newPlainText("text-result", str))
            }
        }

        arguments?.getFloat(TEXT_SIZE_KEY)?.let { textSp ->
            mText.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSp)
        }
    }

    override fun onFindView(rootView: View?) {

    }

    override fun onLayoutId(): Int {
        return R.layout.fragment_text
    }

    override fun onPageExit() {

    }
}